package com.mycode.converter;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.springframework.core.convert.converter.Converter;

public class String2DateConverter implements Converter<String, Date> {
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	@Override
	public Date convert(String str) {
		java.util.Date tmp = null;
		try {
			tmp = sdf.parse(str);
		} catch (ParseException e) {
			tmp = null;
		}
		
		if (tmp != null) {
			return new Date(tmp.getTime());
		} else {
			return null;
		}
	}

}
